<!-- 质保 -->

<template>
	<Card :showBodySlot="ShowBody">
		<template #head>
			<view class="u-flex">
				<view class="u-flex-1">
					质保
				</view>
				<view class="u-flex-1 u-text-right">
					<u-switch v-model="formData.warrantyFlag" active-color="#409EFF" inactive-color="#eee"></u-switch>
				</view>
			</view>
		</template>
		<template #body>
			<CellField required v-model="formData.warranty" label="质保期(单位:月)"></CellField>
			<CellItem required v-model="formData.warrantyStartTime" label="质保开始日期" itemClickType="date-picker-ymd"></CellItem>
		</template>
	</Card>
</template>

<script>
	import Card from '@/components/card/components/cardBaseWrapper.vue'
	import HButton from '@/components/button/index.vue'
	export default {
		components: {
			Card,
			HButton
		},

		data() {

			return {
				formData: {
					warrantyFlag: false,
					warranty: '',
					warrantyStartTime: ''
				}
			}
		},
		computed: {
			ShowBody() {
				return this.formData.warrantyFlag
			}
		},
		methods: {
			validate() {
				if (this.formData.warrantyFlag) {
					let msg = ''
					if (!this.formData.warranty) {
						msg = '输入质保期'
					} else if (!this.formData.warrantyStartTime) {
						msg = '请选择质保开始日期'
					}
					if (!msg) {
						return true
					}
					wx.showToast({
						title: msg,
						icon: 'error'
					})
					return false
				}
				return true
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
